<?php

define ('YAHOO_KEY', 'YOUR_API_KEY_HERE');

function getPage ($url) {
	if (function_exists('curl_init')) {
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
		$retval = curl_exec($ch);
		curl_close ($ch);
		return $retval;
	}
	return file_get_contents($url);
}

class YahooSearch {

	function get () {
		$xml = getPage ($this->url);
		$data = simplexml_load_string ($xml);
		return isset ($data['totalResultsAvailable']) ? (int) $data['totalResultsAvailable'] : 0;
	}

}

class YahooSearchPage extends YahooSearch {

	function __construct ($domain) {
		$this->url =
			"http://search.yahooapis.com/SiteExplorerService/V1/pageData?appid=" .
			YAHOO_KEY .
			"&query=http://" .
			$domain .
			"&results=0";
	}

}

class YahooSearchInlink extends YahooSearch {

	function __construct ($domain) {
		$this->url =
			"http://search.yahooapis.com/SiteExplorerService/V1/inlinkData?appid=" .
			YAHOO_KEY .
			"&query=http://" .
			$domain .
			"&results=0";
	}

}

$y = new YahooSearchPage ('www.bowling-liga.de');
echo $y->get ();

$y = new YahooSearchInlink ('lloc.de');
echo $y->get ();

?>
